﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace designPatterns
{
   

    // 实现部分接口
    interface IImplementation
    {
        /// <summary>
        /// 操作的实现方法
        /// </summary>
        void OperationImplementation();
    }

    // 具体实现类A
    class ConcreteImplementationA : IImplementation
    {
        //重写基类的方法
        public void OperationImplementation()
        {
            Console.WriteLine("具体实现类A的操作");
        }
    }

    // 具体实现类B
    class ConcreteImplementationB : IImplementation
    {
        //重写基类的方法
        public void OperationImplementation()
        {
            Console.WriteLine("具体实现类B的操作");
        }
    }

    // 具体实现类B
    class ConcreteImplementationC : IImplementation
    {
        //重写基类的方法
        public void OperationImplementation()
        {
            Console.WriteLine("具体实现类C的操作");
        }
    }



    // 抽象部分类
    abstract class Abstraction
    {
        protected IImplementation implementation;    //定义一个公共字段,设为保护,用来实例化一个具体实现类的基类
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="implementation"></param>
        public Abstraction(IImplementation implementation)
        {
            this.implementation = implementation;
        }

        //定义一个抽象方法
        public abstract void Operation();
    }

    // 扩展抽象部分类
    class RefinedAbstractionA : Abstraction
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="implementation"></param>
        public RefinedAbstractionA(IImplementation implementation) : base(implementation)
        {

        }

        //覆写 操作方法
        public override void Operation()
        {
            Console.WriteLine("扩展抽象部分的操作A");

            this.implementation.OperationImplementation();
            this.implementation.OperationImplementation();
        }
    }

    // 扩展抽象部分类
    class RefinedAbstractionB : Abstraction
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="implementation"></param>
        public RefinedAbstractionB(IImplementation implementation) : base(implementation)
        {

        }

        //覆写 操作方法
        public override void Operation()
        {
            Console.WriteLine("扩展抽象部分的操作B");

            this.implementation.OperationImplementation();
            this.implementation.OperationImplementation();
        }
    }




    class Program
    {
        static void Main(string[] args)
        {
            // 使用具体实现类A
            IImplementation implementationA = new ConcreteImplementationA();
            Abstraction abstractionA = new RefinedAbstractionA(implementationA);
            abstractionA.Operation();

            // 使用具体实现类B
            IImplementation implementationB = new ConcreteImplementationB();
            Abstraction abstractionB = new RefinedAbstractionB(implementationB);
            abstractionB.Operation();

            Console.ReadLine();
        }
    }




}
